Game xếp hình Tetris C#

1 using System;
2
3 namespace
Tetris
4 {

5     ///
<summary>
6     ///
Descripción breve de Pieza.
7     ///
</summary>
8     
public class Pieza: ICloneable
9     {
10         
private int m_posX, m_posY;
11         
private int m_color;
12         
private int m_rotacion;
13         
private FormaPieza [] formas = new FormaPieza[Constantes.NUM_ROTACIONES];
14
15         
public Pieza()
16         {
17         
18         }
19         
20         
public Pieza(string formaPiezaRotacion1, string formaPiezaRotacion2, string formaPiezaRotacion3, string formaPiezaRotacion4, int color)
21         {
22             m_color = color;
23             m_rotacion =
0;
24             formas[
0] = new FormaPieza(formaPiezaRotacion1);
25             formas[
1] = new FormaPieza(formaPiezaRotacion2);
26             formas[
2] = new FormaPieza(formaPiezaRotacion3);
27             formas[
3] = new FormaPieza(formaPiezaRotacion4);
28             m_posX =
6;
29             m_posY =
0 - alto + 1;
30         }
31
32         
public int this [int y, int x]
33         {
34             
get
35             {
36                 
if (x < 0 || x > Constantes.COLUMNAS_PIEZAS || y < 0 || y > Constantes.FILAS_PIEZAS)
37                     
throw new Exception("El intervalo está fuera del índice");
38                 
else
39                     
return ((FormaPieza)formas[m_rotacion])[y, x];
40             }
41             
set
42             {
43                 
if (!(x < 0 || x > Constantes.COLUMNAS_PIEZAS || y < 0 || y > Constantes.FILAS_PIEZAS))
44                     ((FormaPieza)formas[m_rotacion])[y, x] =
value;
45                 
else
46                     
throw new Exception("El intervalo está fuera del índice");
47             }
48         }
49
50         
public int ancho
51         {
52             
get
53             {
54                 
return ((FormaPieza)formas[m_rotacion]).ancho;
55             }
56         }
57
58         
public int alto
59         {
60             
get
61             {
62                 
return ((FormaPieza)formas[m_rotacion]).alto;
63             }
64         }
65
66         
public int posX
67         {
68             
get
69             {
70                 
return m_posX;
71             }
72             
set
73             {
74                 m_posX =
value;
75             }
76         }
77
78         
public int posY
79         {
80             
get
81             {
82                 
return m_posY;
83             }
84             
set
85             {
86                 m_posY =
value;
87             }
88         }
89
90         
public int color
91         {
92             
get
93             {
94                 
return m_color;
95             }
96             
set
97             {
98                 m_color =
value;
99             }
100         }
101
102         
public void rotarDerecha()
103         {
104             
if (m_rotacion < Constantes.NUM_ROTACIONES - 1)
105                 m_rotacion++;
106             
else
107                 m_rotacion =
0;
108         }
109
110         
public void rotarIzquierda()
111         {
112             
if (m_rotacion > 0)
113                 m_rotacion--;
114             
else
115                 m_rotacion = Constantes.NUM_ROTACIONES -
1;
116         }
117
118         
#region Miembros de ICloneable
119
120         
public object Clone()
121         {
122             Pieza p =
new Pieza();
123             p.formas = (FormaPieza[])
this.formas.Clone();
124             p.m_posY =
this.posY;
125             p.m_posX =
this.posX;
126             p.m_color =
this.color;
127             p.m_rotacion =
this.m_rotacion;
128             
return p;
129         }
130
131         
#endregion
132     }
133 }



Game xếp hình Tetris C# 5.861 lượt xem

Gõ tìm kiếm nhanh...